Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: untangle UNITTESTS and DEBUGBUILD macros #13694

Closed
wants to merge 4 commits into from

Conversation

vszakats
Copy link
Member

@vszakats vszakats commented May 17, 2024

  • fix DEBUGBUILD guards that should be UNITTESTS, in libcurl
    code used by unit tests.
  • fix guards for libcurl functions used in unit tests only.
  • sync UNITTEST attribute between declarations and definitions.
  • drop DEBUGBUILD guard from test unit2600.
  • fix guards for libcurl HSTS code used by both a unit test (unit1660)
    and test0446.
  • update an existing AppVeyor CI job to test the issues fixed.

This fixes building tests with CURLDEBUG enabled but DEBUGBUILD
disabled. This can happen when building tests with CMake with
ENABLE_DEBUG=ON in Release config, or with ENABLE_CURLDEBUG=ON
and without ENABLE_DEBUG=ON. Possibly also with autotools
when using --enable-curldebug without --enable-debug.

Test results:

Ref: #13592 (issue discovery)
Ref: #13689 (CI testing this PR with DEBUGBUILD/CURLDEBUG combinations)
Closes #13694

@vszakats vszakats added the tests label May 17, 2024
@vszakats vszakats marked this pull request as draft May 18, 2024 00:11
@vszakats vszakats changed the title tests: untangle test-related macros tests: untangle test and debug macros May 18, 2024
@vszakats vszakats marked this pull request as ready for review May 18, 2024 12:46
vszakats added a commit to vszakats/curl that referenced this pull request May 18, 2024
Before this patch, building unit tests required `CURLDEBUG` to be set
either via `ENABLE_DEBUG=ON` or `ENABLE_CURLDEBUG=ON`.

After fixing the build issues in curl#13694, the above requirement is no
longer necessary as a workaround. This patch makes unit tests build
unconditionally.

Depends-on: curl#13694
Ref: curl#13697
Follow-up to 39e7c22 curl#11446
Closes #xxxxx
vszakats added a commit to vszakats/curl that referenced this pull request May 18, 2024
Before this patch, building unit tests (= the `testdeps` target)
required `-DCURLDEBUG` be set either via `ENABLE_DEBUG=ON`
or `ENABLE_CURLDEBUG=ON`.

After fixing the build issues in curl#13694, the above requirement is no
longer necessary as a workaround. This patch makes unit tests build
unconditionally.

Depends-on: curl#13694 (fix build issues)
Depends-on: curl#13697 (fix unit test issue revealed by Old Linux CI job)
Follow-up to 39e7c22 curl#11446
Closes curl#13698
vszakats added a commit to vszakats/curl that referenced this pull request May 19, 2024
@github-actions github-actions bot added the CI Continuous Integration label May 19, 2024
@vszakats vszakats requested a review from bagder May 19, 2024 23:41
@@ -54,7 +54,7 @@
#define MAX_HSTS_DATELENSTR "64"
#define UNLIMITED "unlimited"

#ifdef DEBUGBUILD
#if defined(DEBUGBUILD) || defined(UNITTESTS)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

The unit tests assume that DEBUGBUILD is defined as a prereq for running. This change seems to say that you can build with UNITTESTS without DEBUGBUILD ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unit tests (and any other test) are building fine without either DEBUGBUILD or CURLDEBUG. (That is after fixing the places where DEBUGBUILD was used to enable functions for unit tests.)

This is an outlier case where the deltatime variable of a debug feature (CURL_TIME) is actually required for building a unit test.

@bagder
Copy link
Member

bagder commented May 20, 2024

This fixes building tests with CURLDEBUG enabled but DEBUGBUILD disabled

I wish we could drop the distinction completely and just use one of them. I can't remember the difference, I don't think anyone uses them separately. Am I wrong?

@vszakats
Copy link
Member Author

vszakats commented May 20, 2024

This fixes building tests with CURLDEBUG enabled but DEBUGBUILD disabled

I wish we could drop the distinction completely and just use one of them. I can't remember the difference, I don't think anyone uses them separately. Am I wrong?

They are not the same thing, but their names don't make it trivial to figure out which does what exactly:

  • DEBUGBUILD: curl debug features, such as extra output, and envs that allow controlling internals.
  • CURLDEBUG: memory tracking feature, aka 'TrackMemory'. It's an intrusive option that redefines a lot of internal functions, somewhat fragile.

In CMake, DEBUGBUILD always enables CURLDEBUG, but the latter can also be enabled separately. Autotools looks somewhat similar. Both offer separate options to enable them. Makefile.mk also has independent switches. winbuild enables DEBUGBUILD, but never CURLDEBUG. It's probably rare indeed that someone is concsiously using them separately though.

Yet, they are separate and possible to use separately, with quite a bit of breakage around the edges.

The goal of this patch isn't really to untangle these two from each other, but to fix to use the UNITTESTS macro to enable internal functions and features required for building unit tests. This is mandatory for a successful build, unlike DEBUGBUILD and CURLDEBUG which are optional for building tests. (DEBUGBUILD seems required to run them, but I'd have to test this.)

Merging DEBUGBUILD and CURLDEBUG is an option, but something for separate PR(s).

This PR is an attempt to fix all existing build combinations.

@vszakats
Copy link
Member Author

vszakats commented May 20, 2024

There seem to be a few suspicious cases, where DEBUGBUILD and CURLDEBUG are mixed up in the code, too.
E.g. src/tool_operate.c guards some debug features with CURLDEBUG. There is also one case in src/tool_getparam.c + src/tool_cfgable.h. On a quick glance, in lib almost all CURLDEBUG should be DEBUGBUILD.

I think we might consider renaming CURLDEBUG to CURL_TRACK_MEMORY / CURL_DEBUG_MEMORY or something to make its purpose clear and avoid future mis-uses. For DEBUGBUILD, CURL_DEBUG (or anything starting with CURL_ might also work better.

With the list of related open PRs in the air, I'd prefer merging these first, then continue tackling more. Two PRs are blocked by this one: #13705 and #13698.

@vszakats vszakats changed the title tests: untangle test and debug macros tests: untangle unit test and debug macros May 20, 2024
@vszakats vszakats changed the title tests: untangle unit test and debug macros tests: untangle UNITTESTS and DEBUGBUILD macros May 20, 2024
@vszakats vszakats changed the title tests: untangle UNITTESTS and DEBUGBUILD macros build: untangle UNITTESTS and DEBUGBUILD macros May 20, 2024
@vszakats vszakats added the build label May 20, 2024
@jay
Copy link
Member

jay commented May 21, 2024

I wish we could drop the distinction completely and just use one of them. I can't remember the difference, I don't think anyone uses them separately. Am I wrong?

As Viktor mentions above, yes they are separate because CURLDEBUG is (supposed to be) the guard for the trackmemory feature. Typically I run debug builds of curl with DEBUGBUILD but not CURLDEBUG.

I think we might consider renaming CURLDEBUG to CURL_TRACK_MEMORY / CURL_DEBUG_MEMORY or something to make its purpose clear and avoid future mis-uses. For DEBUGBUILD, CURL_DEBUG (or anything starting with CURL_ might also work better.

I'm with you on the first part (maybe something shorter?) but not the second part. Renaming DEBUGBUILD to CURL_DEBUG is confusing to me since we've been using CURLDEBUG for memory tracking.

@vszakats
Copy link
Member Author

vszakats commented May 21, 2024

I'm with you on the first part (maybe something shorter?) but not the second part. Renaming DEBUGBUILD to CURL_DEBUG is confusing to me since we've been using CURLDEBUG for memory tracking.

Indeed, I agree.

If we want to rename them (or one of them), we can brainstorm for new names. Starting with CURL_ would be a plus for namespacing I think. (DEBUGBUILD might be something used by a dependency, though if it didn't happen for 2 decades, it's not likely to happen now.)

Anyway, after tidying this up, I think it will be a little bit harder to make a mistake by copy-pasting existing code or looking up existing uses. CURLDEBUG is used in just a few specific places after these updates.

As for DEBUGBUILD and UNITTESTS, they remain easy to confuse. The former isn't required to build tests, the latter is.
It makes the purpose of these debug features easier to grasp, but it's debatable if this is a strong enough reason for keeping them separate, esp. if new code continues to get them mixed up. I'm not 100% yet, but merging UNITTESTS into DEBUGBUILD might allow dropping the curlu library, by including all debug stuff in the debug libcurl lib, which could then be used by unit tests. This would also mean that DEBUGBUILD would become mandatory for building tests. Which sounds bad at first, but running tests already requires it I think.

edit: merging DEBUGBUILD with UNITTESTS: This doesn't play well with compiling src: UNITTESTS is the build mode for libcurltool. Dropping libcurlu might still be possible regardless of merging.

@jay
Copy link
Member

jay commented May 22, 2024

I can see UNITTESTS being dependent on DEBUGBUILD but not the other way around

vszakats added a commit that referenced this pull request May 27, 2024
Before this patch `ENABLE_DEBUG=ON` always enabled the TrackMemory
(aka `ENABLE_CURLDEBUG=ON`) feature, but required the `Debug` CMake
configration to actually enable curl debug features
(aka `-DDEBUGBUILD`).

Curl debug features do not require compiling with C debug options. This
also made enabling debug features unintuitive and complicated to use.
Due to other issues (subject to PR #13694) it also caused an error in
default (and `Release`/`MinSizeRel`/`RelWithDebInfo`) configs, when
building the `testdeps` target:
```
ld: CMakeFiles/unit1395.dir/unit1395.c.o: in function `test':
unit1395.c:(.text+0x1a0): undefined reference to `dedotdotify'
```
Ref: https://github.com/curl/curl/actions/runs/9037287098/job/24835990826#step:3:2483

Fix it by always defining `DEBUGBUILD` when setting `ENABLE_DEBUG=ON`.
Decoupling this option from the selected CMake configuration.

Note that after this patch `ENABLE_DEBUG=ON` unconditionally enables
curl debug features. These features are insecure and unsuited for
production. Make sure to omit this option when building for production
in default, `Release` (and other not-`Debug`) modes.

Also delete a workaround no longer necessary in GHA CI jobs.

Ref: 1a62b6e (2015-03-03)
Ref: #13583
Closes #13592
@vszakats vszakats mentioned this pull request May 27, 2024
@vszakats vszakats force-pushed the debug-untangle-2 branch 2 times, most recently from c21e7da to 6f51279 Compare May 27, 2024 18:36
- fix `DEBUGBUILD` guards that should be `UNITTESTS`.
- fix guards for libcurl functions used in unit tests only.
- sync `UNITTEST` attribute between declarations with definitions.
- drop `DEBUGBUILD` guard from test `unit2600`.
- fix guards for libcurl code used by both unit tests (`unit1660`)
  and `test0446`.
@vszakats vszakats force-pushed the debug-untangle-2 branch 2 times, most recently from 0081cb3 to 9ccdca8 Compare May 27, 2024 19:14
@vszakats vszakats closed this in fc8e0de May 27, 2024
@vszakats vszakats deleted the debug-untangle-2 branch May 27, 2024 19:17
vszakats added a commit to vszakats/curl that referenced this pull request May 27, 2024
Before this patch, building unit tests (= the `testdeps` target)
required `-DCURLDEBUG` be set either via `ENABLE_DEBUG=ON`
or `ENABLE_CURLDEBUG=ON`.

After fixing the build issues in curl#13694, the above requirement is no
longer necessary as a workaround. This patch makes unit tests build
unconditionally.

Depends-on: curl#13694 (fix build issues)
Depends-on: curl#13697 (fix unit test issue revealed by Old Linux CI job)
Follow-up to 39e7c22 curl#11446
Closes curl#13698
vszakats added a commit that referenced this pull request May 27, 2024
Before this patch, the `testdeps` build target required `-DCURLDEBUG`
be set either via `ENABLE_DEBUG=ON` or `ENABLE_CURLDEBUG=ON` to build
the curl unit tests.

After fixing build issues in #13694, we can drop this requirement and
build unit tests unconditionally.

Depends-on: #13694
Depends-on: #13697 (fix unit test issue revealed by Old Linux CI job)
Follow-up to 39e7c22 #11446
Closes #13698
vszakats added a commit that referenced this pull request May 27, 2024
…uilds

It affected cmake-unity shared-curltool curldebug mingw-w64 gcc builds
when building the `testdeps` target.

Apply the solution already used in `lib/base64.c` and `lib/dynbuf.c`
to fix it.

Also update an existing GHA CI job to test the issue fixed.

```
In file included from curl/lib/version_win32.c:35,
                 from curl/_bld/src/CMakeFiles/curl.dir/Unity/unity_0_c.c:145:
curl/lib/memdebug.h:52:14: error: redundant redeclaration of 'curl_dbg_logfile' [-Werror=redundant-decls]
   52 | extern FILE *curl_dbg_logfile;
      |              ^~~~~~~~~~~~~~~~
In file included from curl/src/slist_wc.c:32,
                 from curl/_bld/src/CMakeFiles/curl.dir/Unity/unity_0_c.c:4:
curl/lib/memdebug.h:52:14: note: previous declaration of 'curl_dbg_logfile' with type 'FILE *' {aka 'struct _iobuf *'}
   52 | extern FILE *curl_dbg_logfile;
      |              ^~~~~~~~~~~~~~~~
curl/lib/memdebug.h:55:44: error: redundant redeclaration of 'curl_dbg_malloc' [-Werror=redundant-decls]
   55 | CURL_EXTERN ALLOC_FUNC ALLOC_SIZE(1) void *curl_dbg_malloc(size_t size,
      |                                            ^~~~~~~~~~~~~~~
curl/lib/memdebug.h:55:44: note: previous declaration of 'curl_dbg_malloc' with type 'void *(size_t,  int,  const char *)' {aka 'void *(long long unsigned int,  int,  const char *)'}
   55 | CURL_EXTERN ALLOC_FUNC ALLOC_SIZE(1) void *curl_dbg_malloc(size_t size,
      |                                            ^~~~~~~~~~~~~~~
[...]
curl/lib/memdebug.h:110:17: error: redundant redeclaration of 'curl_dbg_fclose' [-Werror=redundant-decls]
  110 | CURL_EXTERN int curl_dbg_fclose(FILE *file, int line, const char *source);
      |                 ^~~~~~~~~~~~~~~
curl/lib/memdebug.h:110:17: note: previous declaration of 'curl_dbg_fclose' with type 'int(FILE *, int,  const char *)' {aka 'int(struct _iobuf *, int,  const char *)'}
  110 | CURL_EXTERN int curl_dbg_fclose(FILE *file, int line, const char *source);
      |                 ^~~~~~~~~~~~~~~
```
Ref: https://ci.appveyor.com/project/curlorg/curl/builds/49840554/job/a4aoet17e9qnqx1a#L362

After: https://ci.appveyor.com/project/curlorg/curl/builds/49843735/job/hbo2uah2vj0ns523

Ref: #13689 (CI testing this PR with `DEBUGBUILD`/`CURLDEBUG`/shared-static combinations)
Depends-on: #13694
Depends-on: #13800
Closes #13705
vszakats added a commit that referenced this pull request May 27, 2024
vszakats added a commit that referenced this pull request May 28, 2024
`CURLDEBUG` is meant to enable memory tracking, but in a bunch of cases,
it was protecting debug features that were supposed to be guarded with
`DEBUGBUILD`.

Replace these uses with `DEBUGBUILD`.

This leaves `CURLDEBUG` uses solely for its intended  purpose: to enable
the memory tracking debug feature.

Also:
- autotools: rely on `DEBUGBUILD` to enable `checksrc`.
  Instead of `CURLDEBUG`, which worked in most cases because debug
  builds enable `CURLDEBUG` by default, but it's not accurate.
- include `lib/easyif.h` instead of keeping a copy of a declaration.
- add CI test jobs for the build issues discovered.

Ref: #13694 (comment)
Closes #13718
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build CI Continuous Integration tests
Development

Successfully merging this pull request may close these issues.

None yet

3 participants